package com.aiju.cash.ui.multiple_shops.widget;

import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.aiju.cash.R;
import com.aiju.cash.ui.multiple_shops.bean.BaseMenu;

import java.util.List;

/**
 * 菜单弹窗
 * Created by Administrator on 2017/6/12.
 */

public class MenuPopuWindow extends PopupWindow {
    private MenuLinearLayout mainView;
    Activity mActivity;

    public MenuPopuWindow(Activity paramActivity, List<BaseMenu> data, final MenuClickLister listener) {
        super(paramActivity);
        mActivity = paramActivity;
        //窗口布局
        mainView = new MenuLinearLayout(paramActivity);
        mainView.setData(data);
        setContentView(mainView);
        //设置宽度
        setWidth(MenuLinearLayout.dip2px(paramActivity, 140));
        //设置高度
        setHeight(MenuLinearLayout.dip2px(paramActivity, 93));
        setFocusable(true);
        //设置显示隐藏动画
        setAnimationStyle(R.style.AnimTools);
        //设置背景透明
        setBackgroundDrawable(new ColorDrawable(0));
        mainView.setListener(new MenuLinearLayout.MenuItemCickLister() {
            @Override
            public void onClick(int position) {
                listener.onClick(position);
                dismiss();
            }
        });
        setOnDismissListener(new PopupWindow.OnDismissListener() {
            // 在dismiss中恢复透明度
            public void onDismiss() {
                WindowManager.LayoutParams lp = mActivity.getWindow()
                        .getAttributes();
                lp.alpha = 1f;
                mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                mActivity.getWindow().setAttributes(lp);
            }
        });


    }

    public interface MenuClickLister {
        void onClick(int position);
    }

}
